package cn.dgut.FrontManger;

import cn.dgut.Utils.JDBCUtils;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

@WebServlet("/SignTeacher")
public class SignTeacherServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        Map<String, String[]> parameterMap = request.getParameterMap();
        List<String> list = new ArrayList<>();

        for (Iterator iter = parameterMap.entrySet().iterator(); iter.hasNext(); ) {
            Map.Entry element = (Map.Entry) iter.next();
            String[] value = (String[]) element.getValue();
            for (int i = 0; i < value.length; i++) {
                list.add(value[i]);
            }
        }

        String sql = "INSERT INTO `Teacher` VALUES (null,'"+list.get(0)+"', '123456','"+list.get(1)+"', '"+list.get(2)+"', 'default.png','"+list.get(3)+"','"+list.get(4)+"','"+list.get(5)+"','0');";
        int flag = new JDBCUtils().querySQL(sql);
        HttpSession session = request.getSession(true);
        session.setAttribute("signTeacherFlag", flag);
        response.sendRedirect("/SendResume.jsp");
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}